package com.seven.batchtask;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @工程名:common-utils
 * @author: sevenDay
 * @时间: 2019/3/15 21:16
 * @描述: 批处理任务
 */
public class BatchTaskList {

    private static final int MAX_THREAD = 50;
    private static ThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(MAX_THREAD);

    /**
     * 功能描述
     * @auther: Xiaohong
     * @date: 2019/3/15 21:19
     * @param list
     * @param nThread
     * @param size
     * @param <T>
     */
    public static<T> void  batchTaskByThreadNumber(List<T> list,int nThread,int size){

        List<List<T>> partions = Lists.newArrayList();
        if (nThread>MAX_THREAD){
            throw new IllegalArgumentException("the thread is too big {"+nThread+"} you can use max thread 50");
        }
        int nCountSize = list.size()/nThread;
        for (int i=0;i<nThread;i++){
            final  int j  = i;
            final int fromIndex = j*nCountSize;
            final int toIndex = (j==nThread-1)?list.size():nCountSize*(j+1);
            partions.add(list.subList(fromIndex,toIndex));

        }
    }

    public static void main(String[] args) {
    }


}
